﻿using StudentWeb.DAL;
using StudentWeb.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentWeb.BLL
{
    public class BookBO
    {
        private BookDataDAO dao = new BookDataDAO();

        public IResult GetBookInfo(int bookId)
        {
            var result = dao.GetInfo(bookId);
            return new DataResult(result);
        }

        public IResult InsertOne(BookData data)
        {
            var result = dao.Insert(data) == 1;
            return new DataResult(result);
        }

        public IResult DeleteOne(int bookId)
        {
            var book = new BookData();
            book.Id = bookId;
            var result = dao.Delete(book) == 1;
            return new DataResult(result);
        }

        public IResult Update(BookData book)
        {
            var result = dao.Update(book) == 1;
            return new DataResult(result);
        }

        public IResult Save(BookData book)
        {
            var result = false;
            if (book.Id != 0)
            {
                result = dao.Update(book) == 1;
            }
            else
            {
                result = dao.Insert(book) == 1;
            }
            return new DataResult(result);
        }

        public IResult List()
        {
            var result = dao.GetList();
            return new DataResult(result);
        }
    }
}
